package gui;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;

import client.LogIn;
import client.Main;

public class GenerateReports_GUI extends JFrame implements ActionListener{
	
	Report_GUI rg=null;
	SatRepGUI srg;
	CompRepGUI crg;
	InvRepGUI ir;
	QinRepGUI qir;
	OrdRepGUI org;
	
	//buttons
	public JButton btnBack;
	public JButton btnLogOut;
	public JButton btnQuartIncRep;
	public JButton btnSatisfacRep;
	public JButton btnOrderRep;
	public JButton btnInventoryRep;
	public JButton btnCustomerCompRep;
	
	
	//panels
	JPanel Mainpanel;
	JPanel panelFileComp;
	JPanel panelShowComp;
	JPanel panelTable;
	
	//text input
	JTextArea textInput;	
	
	//labels
	JLabel lblHeader;
	JLabel lblHeaderFileComp;
	JLabel lblHeaderShowComp;
	JLabel lblHeaderTable;
	JLabel lblText;
	JLabel lblOption;
	
	Container contentpane;

	
	public GenerateReports_GUI(){
		
		super();
		contentpane = this.getContentPane();
	    contentpane.setLayout(new BorderLayout(0, 0));
		this.setBounds((int)Main.dim.getWidth()/2-260, (int)Main.dim.getHeight()/2-275, 515, 550);
		this.setResizable(false);
		this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		this.setTitle("Zer Lah - Generate Reports");
		contentpane.add(getPanel(),BorderLayout.CENTER);
		this.setSize(500,400);
		this.setVisible(true);
	}
	

	JPanel getPanel() 
	{	
		if (Mainpanel == null){
			Mainpanel = new JPanel();
			Mainpanel.setSize(500, 400);
			Mainpanel.setLayout(null);
			Mainpanel.add(getBtnBack());
			Mainpanel.add(getBtnCustomerCompRep());
			Mainpanel.add(getLabelHeader());
			Mainpanel.add(getBtnInventoryRep());
			Mainpanel.add(getBtnLogOut());
			Mainpanel.add(getBtnOrderRep());
			Mainpanel.add(getBtnQuartIncRep());
			Mainpanel.add(getBtnSatisfacRep());
		}
		return Mainpanel;
	}
	
	JLabel getLabelHeader()
	{
		if(lblHeader==null)
		{
			lblHeader=new JLabel();
			if(LogIn.usr.getPriv()==1)
				lblHeader.setText("Generate Reports");
			if(LogIn.usr.getPriv()==0)
				lblHeader.setText("Display Reports");
			lblHeader.setBounds(140, 70, 210, 40);
			lblHeader.setFont(new Font(Font.SANS_SERIF ,Font.PLAIN,25));
		}
		return lblHeader;
	}
	
	JButton getBtnBack(){
		
		if (btnBack == null){
			btnBack = new JButton();
			btnBack.setBounds(380, 20, 100, 40);
			btnBack.setText("Back");
		}
		return btnBack;
	}
	
	JButton getBtnLogOut() {
		
		if (btnLogOut == null){
			btnLogOut = new JButton();
			btnLogOut.setBounds(20,20,100,40);
			btnLogOut.addActionListener(this);
			btnLogOut.setText("LogOut");
		}
		return btnLogOut;
	}
	
	JButton getBtnQuartIncRep(){
		
		if (btnQuartIncRep == null){
			btnQuartIncRep = new JButton();
			btnQuartIncRep.setBounds(120, 120, 250, 40);
			btnQuartIncRep.setText("Quarter Income Report");
			btnQuartIncRep.addActionListener(this);
		}
		return btnQuartIncRep;
	}
	
	JButton getBtnSatisfacRep(){
			
			if (btnSatisfacRep == null){
				btnSatisfacRep = new JButton();
				btnSatisfacRep.setBounds(120, 170, 250, 40);
				btnSatisfacRep.setText("Satisfaction Report");
				btnSatisfacRep.addActionListener(this);
			}
			return btnSatisfacRep;
		}
	
	JButton getBtnOrderRep(){
		
		if (btnOrderRep == null){
			btnOrderRep = new JButton();
			btnOrderRep.setBounds(120, 220, 250, 40);
			btnOrderRep.setText("Order Report");
			btnOrderRep.addActionListener(this);
		}
		return btnOrderRep;
	}
	
	JButton getBtnInventoryRep(){
			
			if (btnInventoryRep == null){
				btnInventoryRep = new JButton();
				btnInventoryRep.setBounds(120, 270, 250, 40);
				btnInventoryRep.setText("Inventory Report");
				btnInventoryRep.addActionListener(this);
			}
			return btnInventoryRep;
		}
	
	JButton getBtnCustomerCompRep(){
		
		if (btnCustomerCompRep == null){
			btnCustomerCompRep = new JButton();
			btnCustomerCompRep.setBounds(120, 320, 250, 40);
			btnCustomerCompRep.setText("Costumer Complaint Status Report");
			btnCustomerCompRep.addActionListener(this);
		}
		return btnCustomerCompRep;
	}
	
	


	
	public void actionPerformed(ActionEvent e) {
		
		if(e.getSource() == btnLogOut)
		{
			if(JOptionPane.showConfirmDialog(null,"Are you sure you want to logout?",null,JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION)
			{
				this.setEnabled(false);
				this.setVisible(false);
				Main.main.logOut.doClick();
			}
		}
		
		if(e.getSource() == btnCustomerCompRep)
		{
			hideScreen();
			if(LogIn.usr.getPriv()==1)
			{
				rg=new Report_GUI(1);
				rg.setSize(new Dimension(500, 400));
				rg.btnBack.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e) {
						rg.dispose();
						showScreen();
					}
				});
			}
			if(LogIn.usr.getPriv()==0)
			{
				crg=new CompRepGUI();
				crg.btnBack.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e) {
						crg.dispose();
						showScreen();
					}
				});
			}
		}
		
		if(e.getSource() == btnSatisfacRep)
		{
			hideScreen();
			if(LogIn.usr.getPriv()==1)
			{
				rg=new Report_GUI(2);
				rg.setSize(new Dimension(1000, 400));
				rg.btnBack.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e) {
						rg.dispose();
						showScreen();
					}
				});
			}
			if(LogIn.usr.getPriv()==0)
			{
				srg=new SatRepGUI();
				srg.btnBack.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e) {
						srg.dispose();
						showScreen();
					}
				});
			}
		}
		
		if(e.getSource() == btnInventoryRep)
		{
			hideScreen();
			if(LogIn.usr.getPriv()==1)
			{
				rg=new Report_GUI(3);
				rg.setSize(new Dimension(1000, 400));
				rg.btnBack.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e) {
						rg.dispose();
						showScreen();
					}
				});
			}
			if(LogIn.usr.getPriv()==0)
			{
				ir=new InvRepGUI();
				ir.btnBack.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e) {
						ir.dispose();
						showScreen();
					}
				});
			}
			
		}
		
		if(e.getSource() == btnQuartIncRep)
		{
			hideScreen();
			if(LogIn.usr.getPriv()==1)
			{
				rg=new Report_GUI(4);
				rg.setSize(new Dimension(500, 400));
				rg.btnBack.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e) {
						rg.dispose();
						showScreen();
					}
				});
			}
			if(LogIn.usr.getPriv()==0)
			{
				qir=new QinRepGUI();
				qir.btnBack.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e) {
						qir.dispose();
						showScreen();
					}
				});
			}
		}
		if(e.getSource() == btnOrderRep)
		{
			hideScreen();
			if(LogIn.usr.getPriv()==1)
			{
				rg=new Report_GUI(5);
				rg.setSize(new Dimension(500, 400));
				rg.btnBack.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e) {
						rg.dispose();
						showScreen();
					}
				});
			}
			if(LogIn.usr.getPriv()==0)
			{
				org=new OrdRepGUI();
				org.btnBack.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e) {
						org.dispose();
						showScreen();
					}
				});
			}
		}
	}
	
	void showScreen()
	{
		this.setEnabled(true);
		this.setVisible(true);
	}
	
	void hideScreen()
	{
		this.setEnabled(false);
		this.setVisible(false);
	}
	
	
}
